package com.xuan.core.configuration.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

/**
 * 配置类：MybatisPlus分页插件
 */
@Configuration
public class MybatisPlusPageConfig {

//    @Bean
//    public MybatisPlusInterceptor mPage() {
//
//        MybatisPlusInterceptor mp = new MybatisPlusInterceptor();
//        mp.addInnerInterceptor(new PaginationInnerInterceptor());
//        return mp;
//
//    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {

        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
        return mybatisPlusInterceptor;

    }

    @Bean
    public PaginationInnerInterceptor paginationInnerInterceptor() {

        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
        paginationInterceptor.setMaxLimit(-1L); // 设置最大单页限制数量，默认500条，-1不受限制
        paginationInterceptor.setDbType(DbType.MYSQL);
        paginationInterceptor.setOptimizeJoin(true); // 开启 count 的 join 优化,只针对部分 left join
        return paginationInterceptor;

    }


}
